// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ai.states;

import zombie.ai.State;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.characters.Stats;
import zombie.core.skinnedmodel.advancedanimation.AnimEvent;

public final class FakeDeadAttackState extends State {
    private static final FakeDeadAttackState _instance = new FakeDeadAttackState();

    public static FakeDeadAttackState instance() {
        return _instance;
    }

    @Override
    public void enter(IsoGameCharacter owner) {
        IsoZombie isoZombie = (IsoZombie)owner;
        isoZombie.DirectionFromVector(isoZombie.vectorToTarget);
        isoZombie.setFakeDead(false);
        owner.setVisibleToNPCs(true);
        owner.setCollidable(true);
        String string = "MaleZombieAttack";
        if (owner.isFemale()) {
            string = "FemaleZombieAttack";
        }

        owner.getEmitter().playSound(string);
        if (isoZombie.target instanceof IsoPlayer && !((IsoPlayer)isoZombie.target).getCharacterTraits().Desensitized.isSet()) {
            IsoPlayer isoPlayer = (IsoPlayer)isoZombie.target;
            Stats stats = isoPlayer.getStats();
            stats.Panic = stats.Panic + isoPlayer.getBodyDamage().getPanicIncreaseValue() * 3.0F;
        }
    }

    @Override
    public void execute(IsoGameCharacter owner) {
    }

    @Override
    public void exit(IsoGameCharacter owner) {
    }

    @Override
    public void animEvent(IsoGameCharacter owner, AnimEvent event) {
        IsoZombie isoZombie = (IsoZombie)owner;
        if (event.m_EventName.equalsIgnoreCase("AttackCollisionCheck")
            && owner.isAlive()
            && isoZombie.isTargetInCone(1.5F, 0.9F)
            && isoZombie.target instanceof IsoGameCharacter isoGameCharacter
            && (isoGameCharacter.getVehicle() == null || isoGameCharacter.getVehicle().couldCrawlerAttackPassenger(isoGameCharacter))) {
            isoGameCharacter.getBodyDamage().AddRandomDamageFromZombie((IsoZombie)owner, null);
        }

        if (event.m_EventName.equalsIgnoreCase("FallOnFront")) {
            isoZombie.setFallOnFront(Boolean.parseBoolean(event.m_ParameterValue));
        }

        if (event.m_EventName.equalsIgnoreCase("ActiveAnimFinishing")) {
            isoZombie.setCrawler(true);
        }
    }
}
